<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <%
    
    out.println("您的数据库某表格中的内容如下<br>");

try {
//这里需要com.microsoft.jdbc.sqlserver.SQLServerDriver类文件，给定的三个jar文件放入您的web-inf/lib/下就 ok了
//mssqlserver.jar，msbase.jar，msutil.jar
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
}
catch(ClassNotFoundException e) {
out.println("class not found"+e.toString());
} 

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=eliteweb1"; 
//forTest 
String user="SA"; 
String password="123"; 
Connection conn= DriverManager.getConnection(url,user,password); 
Statement stmt=conn.createStatement();
String sql="select * from STAFF"; 
ResultSet rs=stmt.executeQuery(sql); 
while(rs.next()){
out.println("第一个字段内容：<font color=red>"+rs.getString(1)+"</font> 第二个字段内容：<font color=red>"+rs.getString(2)+"</font><br>");
} 

out.print("数据库操作成功，恭喜你"); 

rs.close(); 
stmt.close(); 
conn.close();

     %>
  </body>
</html>
